package com.my_musc_service.controller;

import com.my_musc_service.common.R;
import com.my_musc_service.entity.SongListUser;
import com.my_musc_service.entity.SongListUserVO;
import com.my_musc_service.service.SongListUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (SongListUser)表控制层
 *
 * @author makejava
 * @since 2021-06-16 21:10:20
 */
@RestController
@RequestMapping("songListUser")
public class SongListUserController {
    /**
     * 服务对象
     */
    @Resource
    private SongListUserService songListUserService;


    @GetMapping("select/all")
    public R selectAll(SongListUser songListUser) {
        List<SongListUser> songListUserList = this.songListUserService.queryAll(songListUser);
        return R.ok().data("songListUserList", songListUserList);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public SongListUser selectOne(Integer id) {
        return this.songListUserService.queryById(id);
    }

    /**
     * 添加关系
     *
     * @param songListUser
     * @return
     */
    @PostMapping("add")
    public R add(@RequestBody SongListUser songListUser) {
        songListUserService.insert(songListUser);
        return R.ok();
    }

    @PostMapping("updateswap")
    public R updateSwapSongIndex(@RequestBody SongListUserVO songListUserVO) {
        Boolean flag = songListUserService.updateSwapSongIndex(songListUserVO);
        return R.ok().data("isUpdate", flag);
    }

    /**
     * 删除关联关系
     *
     * @param songListUser
     * @return
     */
    @PostMapping("delete")
    public R delete(@RequestBody SongListUser songListUser) {
        Integer rows = songListUserService.deleteBySongListUser(songListUser);
        return R.ok();
    }

    /**
     * 批量删除关联关系
     *
     * @param songListUserList
     * @return
     */
    @PostMapping("deleteBatch")
    public R deleteBatch(@RequestBody List<SongListUser> songListUserList) {
        Integer rows = songListUserService.deleteBySongListUserBatch(songListUserList);
        return R.ok();
    }


    /**
     * 批量绑定关联关系
     * @param songListUserList
     * @return
     */
    @PostMapping("addBatch")
    public R addBatch(@RequestBody List<SongListUser> songListUserList){
        Integer rows=songListUserService.addBatch(songListUserList);
        return R.ok().message("批量添加成功");
    }


}
